<template>
  <div class="app-container">
    <!-- 放置表单 -->
    <el-form ref="form" label-width="60px" :model="detailInfo" :rules="rules">
      <el-form-item label="姓名:" prop="username">
        <el-input v-model="detailInfo.username" style="width: 300px" />
      </el-form-item>
      <el-form-item label="手机号:">
        <el-input v-model="detailInfo.mobile" disabled style="width: 300px" />
      </el-form-item>
      <el-form-item label="密码:">
        <el-input v-model="detailInfo.password" type="password" disabled style="width: 300px" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="updateInfo">更新</el-button>
        <el-button>返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { saveUserDetailByIdAPI } from '@/api/user'
export default ({
  props: {
    detailInfo: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      rules: {
        username: [{ required: true, min: 1, max: 6, message: '用户名必填！', trigger: 'change' }]
      }
    }
  },
  methods: {
    updateInfo() {
      this.$refs.form.validate(async(isok) => {
        if (isok) {
          const res = await saveUserDetailByIdAPI(this.detailInfo)
          console.log(res)
          this.$message.success('更新成功')
        }
      })
    }
  }
})
</script>

